package top.chengdongqing.mishop.order.vo

import com.fasterxml.jackson.annotation.JsonFormat
import top.chengdongqing.mishop.entities.Order
import top.chengdongqing.mishop.enums.OrderStatus
import top.chengdongqing.mishop.enums.PaymentMethod
import java.io.Serializable
import java.math.BigDecimal
import java.time.LocalDateTime

data class OrderVO(
    val id: Int,
    val orderNumber: String,
    val productsAmount: BigDecimal,
    val shippingFee: BigDecimal,
    val discountAmount: BigDecimal,
    val paidAmount: BigDecimal,
    val recipientName: String,
    val recipientPhone: String,
    val recipientAddress: String,
    val paymentMethod: PaymentMethod?,
    val expressName: String?,
    val trackingNumber: String?,
    val isReviewed: Boolean,
    val status: OrderStatus,
    val items: List<OrderItemVO>,
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    val createdAt: LocalDateTime?
) : Serializable {
    companion object {
        fun of(order: Order): OrderVO {
            return OrderVO(
                id = order.id,
                orderNumber = order.orderNumber,
                productsAmount = order.productsAmount,
                shippingFee = order.shippingFee,
                discountAmount = order.discountAmount,
                paidAmount = order.paidAmount,
                recipientName = order.recipientName,
                recipientPhone = order.recipientPhone,
                recipientAddress = order.recipientAddress,
                paymentMethod = order.paymentMethod,
                expressName = order.expressName,
                trackingNumber = order.trackingNumber,
                isReviewed = order.isReviewed,
                status = order.status,
                items = OrderItemVO.of(order.items),
                createdAt = order.createdAt
            )
        }
    }
}
